package com.ruicar.afs.cloud.account.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.modules.contract.enums.VoucherSendStatus;
import com.ruicar.afs.cloud.common.vo.VoucherInfoVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/22 10:07
 */
@TableName("account_voucher_info")
@Data
public class AccountVoucherInfo  {

    private static final long serialVersionUID = 1L;
    @ApiModelProperty("唯一标识")
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @JSONField(
            serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class
    )
    @TableId(
            value = "id",
            type = IdType.ASSIGN_ID
    )
    private Long id;

    @ApiModelProperty("凭证流水号")
    @NotBlank(message = "凭证流水号不能为空")
    private String voucherSerialNumber ;

    @ApiModelProperty("凭证号")
    @NotBlank(message = "凭证号不能为空")
    private String voucherNo ;

    @ApiModelProperty("摘要")
    private String explanation ;

    @ApiModelProperty("主业务事件")
    @NotBlank(message = "主业务事件不能为空")
    private String mainBusiness;

    @ApiModelProperty("主事件代码")
    @NotBlank(message = "主事件代码不能为空")
    private String mainBusinessCode;

    @ApiModelProperty("子业务事件")
    @NotBlank(message = "子业务事件不能为空")
    private String childBusiness;

    @ApiModelProperty("子事件代码")
    @NotBlank(message = "子事件代码不能为空")
    private String childBusinessCode;

    @ApiModelProperty("合同号")
    private String contractNo ;

    @ApiModelProperty("总金额")
    private BigDecimal totalAmount;

    @ApiModelProperty("供应商名称")
    @NotBlank(message = "供应商名称不能为空")
    private String dealerName ;

    @ApiModelProperty("业务交易流水号")
    private String businessNo ;

    @ApiModelProperty("会计年度")
    private String fiscalYear ;

    @ApiModelProperty("会计期间")
    private String accountingPeriod ;

    @ApiModelProperty("制单日期")
    private Date preparedDate ;

    @ApiModelProperty("记账日期")
    private Date postingDate ;

    private Date sendingDate ;

    @ApiModelProperty("来源系统")
    private String sourceSystem ;

    @ApiModelProperty("交易状态 枚举值：待发送，成功，失败")
    @NotNull(message = "交易状态不能为空")
    private VoucherSendStatus status;

    @ApiModelProperty("冲销凭证号")
    private String reversalVoucherNo ;

    @ApiModelProperty("案件类型")
    private String caseType;

    @ApiModelProperty("错误信息")
    private String errMsg ; @ApiModelProperty("创建者")
    @TableField(
            fill = FieldFill.INSERT
    )
    private String createBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("创建时间")
    @TableField(
            fill = FieldFill.INSERT
    )
    private Date createTime;
    @ApiModelProperty("更新者")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private String updateBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("更新时间")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private Date updateTime;


    public static AccountVoucherInfo convertFrom(VoucherInfoVo voucherInfo){
        AccountVoucherInfo info = new AccountVoucherInfo();
        info.setMainBusiness(voucherInfo.getMainBusiness());
        info.setMainBusinessCode(voucherInfo.getMainBusinessCode());
        info.setChildBusiness(voucherInfo.getChildBusiness());
        info.setChildBusinessCode(voucherInfo.getChildBusinessCode());
        info.setExplanation(voucherInfo.getChildBusiness());// 采用借方第一个摘要
        return info;
    }
}
